package StudyCode.summary.mycollection;

import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UsingSortedSetsAndTreeSets {
	public static void main(String[] args) {
		String[] colors = {"yellow", "green", "black", "tan", "grey",
				"white", "orange", "red", "green"};
		SortedSet<String> tree = new TreeSet<>(Arrays.asList(colors));

		System.out.print("sorted set: ");
		printSet(tree);

		System.out.print("headSet (\"orange\"):  ");
		printSet(tree.headSet("orange"));

		System.out.print("tailSet (\"orange\"):  ");
		printSet(tree.tailSet("orange"));

		System.out.printf("第一个: %s%n", tree.first());
		System.out.printf("最后一个 : %s%n", tree.last());
	}

	private static void printSet(SortedSet<String> set) {
		for (String s : set)
			System.out.printf("%s ", s);

		System.out.println();
	}
}
